nums = [5,7,7,8,8,10], target = 8

var searchRange = function(nums, target) {
   function findFirst(){
    let left=0 
    let right=nums.length-1
    let res=-1
    while(left<=right)
    {
        let mid=Math.floor((left+right)/2)
        if(nums[mid]>=target)
        {
            right=mid-1;
            if(nums[mid]==target)res=mid
        }
        else left=mid+1
    }
    return res
   }
   function findLast(){
     let left=0 
    let right=nums.length-1
    let res=-1
    while(left<=right)
    {
        let mid=Math.floor((left+right)/2)
        if(nums[mid]<=target){
            left=mid+1
            if(nums[mid]===target)res=mid
        }
        else right=mid-1
    }
    return res
   }
   const first=findFirst()
   const last=findLast()
   return first !== -1 ? [first, last] : [-1, -1];
}

console.log(searchRange(nums,target));
